﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.States.GameState.Entities;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
using ElfTyping.States.GameState.Effects;
using Microsoft.Xna.Framework;
using ElfTyping.States.GameState.PlayerSpells;
using ElfTyping.General;

namespace ElfTyping.States.GameState
{
    public class GameScript
    {
        GameState gameState;

        //public Entity CallerEntity { private get; set; }

        public GameScript(GameState gameStateParent)
        {
            gameState = gameStateParent;
        }


        public void AddEnemyToAttack(Enemy self)
        {
            //Debug.Assert(self == CallerEntity);

            gameState.EnemiesToAttack.Add(self);
        }

        public void EnemyDeath(Enemy self)
        {
            //Debug.Assert(self == CallerEntity);

            gameState.GainExperience(self.Experience);
            gameState.RemoveEnemy(self);
            SpawnEffect(new DeathEffect(self), false);
        }

        public void SpawnEnemy(Enemy newEnemy)
        {
            gameState.EnemiesToBeSpawned.Add(newEnemy);
        }

        public void SpawnEffect(GameEffect effect)
        {
            SpawnEffect(effect, true);
        }

        public void SpawnEffect(GameEffect effect, bool isForegroundEffect)
        {
            effect.Script = this;

            if (isForegroundEffect)
            {
                gameState.ForegroundEffectsToBeStarted.Add(effect);
            }
            else
            {
                gameState.BackgroundEffectsToBeStarted.Add(effect);
            }
        }

        public GameScript NewScript()
        {
            return new GameScript(gameState);
        }

        public Rectangle GetPlayerDrawBox()
        {
            return gameState.Player.DrawBox;
        }

        public void HealPlayer(int health)
        {
            gameState.Player.GainHealth(health);
        }

        public void CastSpell(PlayerSpell spell)
        {
            SpawnEffect(spell.Effect);
        }

        public List<Enemy> GetEnemies()
        {
            return gameState.EnemyList;
        }

        public void DropRandomPuzzlePiece(Enemy self)
        {
            gameState.Player.GainPuzzlePiece();
        }

        public void AddEventIn(float secondsFromNow, GameState.EventManager.EventAction action)
        {
            gameState.AddEventIn(secondsFromNow, action);
        }
    }
}
